<html>
<head><meta charset="utf-8"><title>Filepath Bikeshedding · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Filepath.20Bikeshedding.html">Filepath Bikeshedding</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="202147149"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Filepath%20Bikeshedding/near/202147149" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Maurer <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Filepath.20Bikeshedding.html#202147149">(Jun 26 2020 at 21:55)</a>:</h4>
<p>If you were defining guidelines for a new project, which of <code>foo/{mod.rs,bar.rs}</code> or <code>foo.rs,foo/bar.rs</code> would you select and why?<br>
I see that rustc still heavily uses <code>mod.rs</code>, but that might be legacy rather than preference.</p>



<a name="202147439"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Filepath%20Bikeshedding/near/202147439" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Filepath.20Bikeshedding.html#202147439">(Jun 26 2020 at 21:58)</a>:</h4>
<p>One benefit of <code>foo.rs,foo/bar.rs</code> is that you won't ever have multiple <code>mod.rs</code> files open, which can make editor navigation easier</p>



<a name="202147486"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Filepath%20Bikeshedding/near/202147486" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Filepath.20Bikeshedding.html#202147486">(Jun 26 2020 at 21:59)</a>:</h4>
<p>I still use <code>mod.rs</code> though, since it's what I'm used to and rustc doesn't yell at me (hard to defeat muscle memory)</p>



<a name="202147489"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Filepath%20Bikeshedding/near/202147489" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Filepath.20Bikeshedding.html#202147489">(Jun 26 2020 at 21:59)</a>:</h4>
<p>(OTOH, it means that auto-completion is a pain, at least I always feel like I'm hitting tab and typing way too many times)</p>



<a name="202147528"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Filepath%20Bikeshedding/near/202147528" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Filepath.20Bikeshedding.html#202147528">(Jun 26 2020 at 21:59)</a>:</h4>
<p>I think some of that is "insufficiently smart" autocomplete.</p>



<a name="202147608"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Filepath%20Bikeshedding/near/202147608" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Filepath.20Bikeshedding.html#202147608">(Jun 26 2020 at 22:00)</a>:</h4>
<p>rust-analyzer has a "create module" assist when writing <code>mod foo;</code> and there's no matching file; I think it will always use the <code>foo.rs; foo/bar.rs</code> pattern.</p>



<a name="202147733"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Filepath%20Bikeshedding/near/202147733" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Maurer <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Filepath.20Bikeshedding.html#202147733">(Jun 26 2020 at 22:01)</a>:</h4>
<p>Hm, that last one is a bit compelling, since we're planning on having rust-analyzer be the IDE support for devs. It'd be kind of awkward to have the tooling we give them violate their style guide.</p>



<a name="202147879"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Filepath%20Bikeshedding/near/202147879" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Filepath.20Bikeshedding.html#202147879">(Jun 26 2020 at 22:02)</a>:</h4>
<p>I have been using <a href="http://foo.rs">foo.rs</a> foo/bar.rs for the last couple years and it's not been terrible</p>



<a name="202147945"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Filepath%20Bikeshedding/near/202147945" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Filepath.20Bikeshedding.html#202147945">(Jun 26 2020 at 22:03)</a>:</h4>
<p>realistically you're pretty rarely typing these paths anyway, hopefully, but rather using things like goto definition and fuzzy matching the path</p>



<a name="202148851"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Filepath%20Bikeshedding/near/202148851" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Maurer <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Filepath.20Bikeshedding.html#202148851">(Jun 26 2020 at 22:11)</a>:</h4>
<p>Yeah, it's not super important, but the codebase in question is large so if use becomes extensive I'd like everything to be done the same way so it's predictable across the codebase.</p>
<p>I'm going to recommend <code>foo.rs,foo/bar.rs</code> for now; thanks for the feedback.</p>



<a name="202160380"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Filepath%20Bikeshedding/near/202160380" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Filepath.20Bikeshedding.html#202160380">(Jun 27 2020 at 01:14)</a>:</h4>
<blockquote>
<p>you won't ever have multiple <a href="http://mod.rs">mod.rs</a> files </p>
</blockquote>
<p>And then you get bigger and have multiple crates and then you are back to the same problem with <code>lib.rs</code> <span aria-label="wink" class="emoji emoji-1f609" role="img" title="wink">:wink:</span></p>



<a name="202168776"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Filepath%20Bikeshedding/near/202168776" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Filepath.20Bikeshedding.html#202168776">(Jun 27 2020 at 05:15)</a>:</h4>
<p>The "obvious" fix is to declare all folders as inline modules and avoid both <code>foo.rs</code> and <code>foo/mod.rs</code> entirely</p>



<a name="202168847"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Filepath%20Bikeshedding/near/202168847" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Filepath.20Bikeshedding.html#202168847">(Jun 27 2020 at 05:17)</a>:</h4>
<p><code>lib.rs</code></p>
<div class="codehilite"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">mod</span> <span class="nn">foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="k">pub</span><span class="w"> </span><span class="k">mod</span> <span class="nn">bar</span><span class="p">;</span><span class="w"></span>
<span class="w">  </span><span class="k">pub</span><span class="w"> </span><span class="k">mod</span> <span class="nn">zap</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>


<p><code>foo/bar.rs</code> and <code>foo/zap.rs</code> then hold whatever you want</p>



<a name="202170290"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Filepath%20Bikeshedding/near/202170290" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Peter Rabbit <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Filepath.20Bikeshedding.html#202170290">(Jun 27 2020 at 06:02)</a>:</h4>
<p>The issue with having multiple <code>mod.rs</code> is definitely making me consider the alternative. I might switch to <code>um.rs,um/winuser.rs</code> in winapi 0.4.</p>



<a name="202174358"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Filepath%20Bikeshedding/near/202174358" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Charles Lew <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Filepath.20Bikeshedding.html#202174358">(Jun 27 2020 at 08:11)</a>:</h4>
<p>If you don't use <code>mod.rs</code>, then be careful if you're also using <code>#[path]</code>, <a href="https://github.com/rust-lang/rust/issues/59345">https://github.com/rust-lang/rust/issues/59345</a> . IMO it's a little annoying behavior...</p>



<a name="202176032"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Filepath%20Bikeshedding/near/202176032" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Filepath.20Bikeshedding.html#202176032">(Jun 27 2020 at 08:58)</a>:</h4>
<p>I prefer <code>mod.rs</code> as it means that the module and it's submodules are close to each other in the file tree. Having multiple <code>mod.rs</code> is not an issue in vscode at least, as it shows dir names as necessary to disambiguate between files with identical names.</p>



<a name="202176116"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Filepath%20Bikeshedding/near/202176116" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Poliorcetics <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Filepath.20Bikeshedding.html#202176116">(Jun 27 2020 at 09:01)</a>:</h4>
<p>I use vscode too and still prefer the <a href="http://foo.rs">foo.rs</a> and foo/bar.rs version, though I tend to write some modules as <span class="user-mention" data-user-id="224471">@Lokathor</span> showed, with a mod statement in <a href="http://lib.rs">lib.rs</a>, especially when it’s just used to separate concerns without introducing code other than « pub use » in <a href="http://foo.rs">foo.rs</a></p>



<a name="202176157"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Filepath%20Bikeshedding/near/202176157" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Poliorcetics <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Filepath.20Bikeshedding.html#202176157">(Jun 27 2020 at 09:02)</a>:</h4>
<p>Ugh, Typing code blocks on mobile is a pain</p>



<a name="202394056"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Filepath%20Bikeshedding/near/202394056" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Filepath.20Bikeshedding.html#202394056">(Jun 30 2020 at 04:14)</a>:</h4>
<p>I prefer not using <code>mod.rs</code>, because I like my module paths to match my file paths.</p>



<a name="202394071"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Filepath%20Bikeshedding/near/202394071" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Filepath.20Bikeshedding.html#202394071">(Jun 30 2020 at 04:15)</a>:</h4>
<p>Especially when I see <code>foo::bar::thing</code> and wonder where that is.</p>



<a name="202411716"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Filepath%20Bikeshedding/near/202411716" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> DPC <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Filepath.20Bikeshedding.html#202411716">(Jun 30 2020 at 09:17)</a>:</h4>
<p>i end up with <code>mod.rs</code>because pre-2018 habits :P Most people don't like <code>mod.rs</code> because they don't like 100 <code>mod.rs</code> tabs in their editor and have to remember which is which</p>



<a name="202416546"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Filepath%20Bikeshedding/near/202416546" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Filepath.20Bikeshedding.html#202416546">(Jun 30 2020 at 10:12)</a>:</h4>
<p>I feel like rustc should really warn about the <code>mod.rs</code> syntax to nudge people away from it. This would have made me instantly switch with no complaints.</p>



<a name="202418597"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Filepath%20Bikeshedding/near/202418597" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Filepath.20Bikeshedding.html#202418597">(Jun 30 2020 at 10:38)</a>:</h4>
<p>I think the biggest issue with <code>mod.rs</code> is that you need to rename/move files when you want to add a submodule</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>